package top.frsf.mqtt.handler.strategy;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.mqtt.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.frsf.mqtt.handler.strategy.abs.MqttMessageHandlerStrategy;

/**
 * MQTT协议事件 - 心跳事件处理器
 *
 * @author He Kuntao
 * @since 2025/5/30 14:00
 */
@Slf4j
@Component
public class PingReqMessageHandler implements MqttMessageHandlerStrategy {
    @Override
    public void handle(ChannelHandlerContext ctx, MqttMessage message) {
        log.info("PingReqMessageHandler");
        MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
        MqttMessage mqttMessage = new MqttMessage(fixedHeader);
        ctx.writeAndFlush(mqttMessage);
    }

    @Override
    public MqttMessageType supportedType() {
        return MqttMessageType.PINGREQ;
    }
}
